#include <iostream>
#include <string>
using namespace std;
#define DEBUG
int n, sum;

bool check(int x)
{
    if(x%7==0) return true;
    while(x) 
    {
        if(x%10==7) return true;
        x/=10;
    }
    return false;
}

int main()
{
    #ifdef DEBUG
        freopen("./in.txt", "r", stdin);
        freopen("./out.txt", "w", stdout);
    #endif

    int n;
    cin >> n;
    for(int i=1; i<=n; i++) if(!check(i)) sum+=i;
    cout << sum << endl;
    return 0;
}